home *** CD-ROM | disk | FTP | other *** search
- Path: worf.qntm.com!root
- From: pb@netcom.com
- Newsgroups: comp.lang.c
- Subject: Re: Best way to make a circle
- Date: 12 Feb 1996 20:09:33 GMT
- Organization: Quantum Corp. Milpitas CA USA
- Message-ID: <4fo6pt$39o@worf.qntm.com>
- References: <1996Feb8.043040.19301@lafn.org>
- Reply-To: pb@netcom.com
- NNTP-Posting-Host: pbutler.qntm.com
- X-Newsreader: IBM NewsReader/2 v1.02
-
- In <1996Feb8.043040.19301@lafn.org>, an234@lafn.org (Andres Lessing) writes:
- >
- >I am working on 3d Graphics quite succesfully as of now and am trying to
- >put together a good Graphics library that is much faster than BGI drivers.
- >I know that Sin and Cosine take to much time to calculate... so... which
- >way should I do it?
- >
- First a little math...
- Circle: x = sin(t)
- y = cos(t) step t from 0..2pi
-
- difer: dx = +cos(t)/dt
- dy = -sin(t)/dt
-
- subst: dx = +y/dt
- dy = -x/dt
-
- let dt=1/64 and we have in c
-
- x += y/64;
- y -= x/64; /* rad/64 or about 400 steps around */
-
- if we let m = 2pi/steps we get...
-
- x += m*y;
- y -= m*x; /* 'tiz better to use the new x in this step */
-
- Using the above you step sin/cos using simple math. Properly scaled 16 bit values
- aint bad. Test in spread sheet if you wish. Dont forget to reset to (x=0, y=1)
- after one trip around or you get a growing circle.
-
- -pb
-
-